package com.minisoft.aop;

import cn.hutool.json.JSONObject;

import java.util.Map;

public class BuildingInfoService {

    private final PropertyChangeAspect propertyChangeAspect = new PropertyChangeAspect();

    public void updateBuildingInfo(JSONObject obj) {
        // 初始化变化记录
        propertyChangeAspect.clearChanges();

        BuildingInfo entity = new BuildingInfo();
        // 创建代理对象
        BuildingInfo proxy = PropertyChangeAspect.createProxy(entity);

        entity.setBuildingIdYx(obj.getStr("YXLDID"));
        entity.setBuildingIdErp(obj.getStr("POSID"));
        entity.setProductId(obj.getStr("CPLX_CODE"));
        entity.setProductName(obj.getStr("PROD_TYPE_DES"));
        entity.setSubProductId(obj.getStr("ZSSCP"));
        entity.setSubProductName(obj.getStr("ZSSCP_DES"));
        entity.setZxbzId(obj.getStr("ZXBZ_ID"));
        entity.setJysxId(obj.getStr("JYSX_ID"));
        entity.setDjlxId(obj.getStr("DJLX_ID"));
        entity.setCkywcqId(obj.getStr("CKYWCQ_ID"));

        // 获取所有发生变化的属性
        Map<String, Object> changes = propertyChangeAspect.getChanges();
        System.out.println("Changed properties: " + changes);

        // 清除变化记录
        propertyChangeAspect.clearChanges();
    }

    public static void main(String[] args) {
        BuildingInfoService service = new BuildingInfoService();
        JSONObject obj = new JSONObject();
        obj.put("YXLDID", "YXLDID");
        obj.put("POSID", "POSID");
        obj.put("CPLX_CODE", "CPLX_CODE");
        obj.put("PROD_TYPE_DES", "PROD_TYPE_DES");
        obj.put("ZSSCP", "ZSSCP");
        obj.put("ZSSCP_DES", "ZSSCP_DES");
        obj.put("ZXBZ_ID", "ZXBZ_ID");
        obj.put("JYSX_ID", "JYSX_ID");
        obj.put("DJLX_ID", "DJLX_ID");
        obj.put("CKYWCQ_ID", "CKYWCQ_ID");
        service.updateBuildingInfo(obj);
    }
}